{template header}
<div class="container">


<div class="row">

<div class="col-md-8">

    <div class="panel panel-default">
        <div class="panel-body">
            {template top}
        </div>
    </div>



    <div class="panel panel-default" id="info">
        <div class="panel-body" style="position: relative;">
            <div style="position: absolute;right: 15px;top: 15px;"><a class="btn btn-success"  href="javascript:void('0');" onclick="dutyCount('{$groupid}','0')">月统计</a></div>
            <ul class="nav nav-pills">
                {if $strGroup['isplace']>0}
                {if !isMobile()}
                <li role="presentation"><a href="{tsUrl('group','show',array('id'=>$strGroup[groupid]))}#info">文档</a></li>
                <li role="presentation"  class="active"><a href="{tsUrl('group','duty',array('id'=>$strGroup[groupid]))}#info">服务</a></li>
                <li role="presentation"><a href="{tsUrl('group','acount',array('id'=>$strGroup[groupid]))}#info">账目</a></li>
                {else}
                <li>
                    <select onchange="jump(this.options[this.options.selectedIndex].value)" name="typeid" id="typeid" class="form-control">
                        <option value="{tsUrl('group','show',array('id'=>$strGroup[groupid]))}#info">文档</option>
                        <option value="{tsUrl('group','duty',array('id'=>$strGroup[groupid]))}#info"  selected>服务</option>
                        <option value="{tsUrl('group','acount',array('id'=>$strGroup[groupid]))}#info" >账目</option>
                    </select>
                </li>
                {/if}
                {/if}
            </ul>




<div class="topic_list">
<ul>

{loop $arrDuty $key $item}
<li>
<div class="userimg">
<a href="{tsUrl('user','duty',array('id'=>$item[user][userid]))}" rel="face" uid="{$item['user']['userid']}"><img class="img-circle" src="{$item[user][face]}" width="32" height="32" alt="{$item['user']['username']}" title="{$item['user']['username']}" /></a>
</div>

<div class="topic_title">
<div class="title">

    <a href="{tsUrl('user','duty',array('id'=>$item[userid]))}"  rel="face" uid="{$item['user']['userid']}">{$item[user][username]}</a><span style="float: right;color: #c0c0c0">{$item[count_recommend]} 赞</span>

</div>

<div style="color:{if $item['status']==0}#c0c0c0{else}#000000{/if}" >
    {if $item['endtime']==0}{php echo date('Y-m-d',$item['begintime'])}{else}{php echo date('Y-m-d H:i',$item['begintime'])}至{php echo date('H:i',$item['endtime'])}{/if}在{$item[group][groupname]}执行{$item['cate']}，{if $item['commute']==0}服务{php echo $item['period']}小时{else}实际服务{$item['period']}小时，通勤时间{php echo $item['commute']}小时，合计耗时{php echo $item['term']}小时{/if}。<br/>{if $item['job']}<br/>{php echo delempty($item['job'])}{/if}&nbsp;&nbsp;
</div>
    {if $item['image']}

    <div class="piclist">
        <ul>
            {loop $item['image'] $k $pic}
            <li style="border-bottom: none"><a href="{$pic}"><img style="width:100px;height: auto;position:absolute; clip:rect(0px 120px 70px 0px); " src="{$pic}"></a></li>

            {/loop}
        </ul>
    </div>
    {/if}
    {if $item['comment']}

    <ul style="background-color: #f7f7f7;border-radius: 5%;margin-top: 20px">
        {loop $item['comment'] $k $v}
        <li style="border-bottom: 0px;">
            <div class="userimg"><a href="{tsUrl('user','duty',array('id'=>$v[user][userid]))}"><img class="img-rounded" src="{$v[user][face]}" width="32" height="32" alt="{$v['user']['username']}" title="{$v['user']['username']}" /></a></div>
            <div class="topic_title">
                <div class="title">
                    <div class="author"><a href="{tsUrl('user','duty',array('id'=>$v[user][userid]))}">{$v[user][username]}</a>&nbsp;&nbsp;{php echo getTime($v[addtime],time())}</div>
                    <div class="content">{$v[content]}</div>
                </div>
            </div>

        </li>

        {/loop}
    </ul>

    {/if}
</div>
    <div class="tar">
        {if $GLOBALS[TS_USER][userid]==$item['userid']&&$item['status']==1}

        <a class="btn btn-w" style="background-color: #419641;color: #FFFFFF" href="{tsUrl('duty','card',array('dutyid'=>$item[dutyid]))}">打卡</a>

        {/if}

        {if $item['articleid']>0}
        <a class="btn btn-w" href="{tsUrl('article','show',array('id'=>$item[articleid]))}">读文档</a>
        {/if}

        {if $GLOBALS[TS_USER][userid]==$item['userid']}

        <a class="btn btn-w"  href="javascript:void('0');" onclick="doBindForm('{php echo($key*1+1)}')">绑定文档</a>

        {/if}

        {if $item['status']==0&&($GLOBALS['TS_USER']['isadmin']=='1'||$GLOBALS[TS_USER][userid]==$item['userid'])}<a  class="btn btn-w" href="{tsUrl('duty','show',array('dutyid'=>$item[dutyid],'edit'=>1))}" >修改</a>{/if}
        {if $item['status']==0&&($GLOBALS['TS_USER']['isadmin']=='1'||$GLOBALS[TS_USER][userid]==$item['userid'])}<a  class="btn btn-w" href="javascript:void('0');" onclick="delDuty('{$item['dutyid']}')">删除</a>{/if}
        {if (in_array($GLOBALS[TS_USER][userid],$item['group']['admin'])||$GLOBALS['TS_USER']['isadmin']=='1')&&$item['status']==0}<a class="btn btn-w" href="javascript:void('0');" onclick="verify('{$item['dutyid']}')">核定</a>{/if}
        {if (in_array($GLOBALS[TS_USER][userid],$item['group']['admin'])||$GLOBALS['TS_USER']['isadmin']=='1')&&$item['status']==1}<a class="btn btn-w" href="javascript:void('0');" onclick="cancel('{$item['dutyid']}')">取消核定</a>{/if}
        {if $GLOBALS[TS_USER][userid]&&$item['status']==1&&$item[userid]!=$GLOBALS[TS_USER][userid]}
        <a class="btn btn-w" href="javascript:void('0');" onclick="recommend('{$item[dutyid]}')">{if $item[isrecommend]==0} 点赞{else} 取消点赞{/if}</a>
        {/if}
        {if $GLOBALS[TS_USER][userid]>0}
        <a class="btn btn-w" href="javascript:void(0)" onclick="add_comment('{$item[dutyid]}')">评论</a>
        {/if}

    </div>
<div class="clear"></div>
</li>
{/loop}

</ul>
</div>
<div class="page">{$pageUrl}</div>
</div>
</div>

</div>
    {template right}
</div>
</div>

<div id="countDuty" class="modal fade">
    <div class="modal-dialog">
        <div class="modal-content" style="height:{php echo($strGroup['count_user']*45)}px">
            <div class="modal-header" style="text-align: center">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h5 class="modal-title" style="margin-left:10%;">
                    <select onchange="dutyCount('{$groupid}',this.options[this.options.selectedIndex].value)" class="form-control" style="width: 60%">
                    <option value="0">本月</option>
                    {for $x=1; $x<=12;$x++ }
                    <option value="{$x}">{$x}个月前</option>
                    {/if}
                </select>
                </h5>
            </div>
                <div class="modal-body" >
                    <div class="form-group">
                        <div class="col-md-12">
                            <div id="dutytable"></div>
                        </div>
                    </div>
                </div>
        </div>
    </div>
</div>


<script>
    //绑文档
    function doBindForm(key){

        if(key==0){
            tsNotice('非法操作！');
        }else{
            var content = $("#do_bind_form"+key).html();
            tsNotice(content);
        }
    }
    //删除服务记录
    function delDuty(dutyid){


        if (confirm('删除这条服务记录吗？')) {

            $.ajax({
                type: "POST",
                url: siteUrl+"index.php?app=user&ac=do&ts=del",
                data: "dutyid="+dutyid,
                beforeSend:function(){
                },
                success:function(result){
                    if(result == '1'){
                        window.location.reload();
                    }
                }
            });

        }
    }
    //确认服务记录
    function verify(dutyid){


        if (confirm('确认这条服务记录吗？')) {

            $.ajax({
                type: "POST",
                url: siteUrl+"index.php?app=user&ac=do&ts=verify",
                data: "dutyid="+dutyid,
                beforeSend:function(){
                },
                success:function(result){
                    if(result == '1'){
                        window.location.reload();
                    }
                }
            });

        }
    }

    //取消确认
    function cancel(dutyid){

        if (confirm('取消确认这条服务记录吗？')) {

            $.ajax({
                type: "POST",
                url: siteUrl+"index.php?app=user&ac=do&ts=cancel",
                data: "dutyid="+dutyid,
                beforeSend:function(){
                },
                success:function(result){
                    if(result == '1'){
                        window.location.reload();
                    }
                }
            });
        }
    }

    //小组成员值班统计


    function dutyCount(groupid,first){

        $.ajax({
            url: 'index.php?app=group&ac=ajax&ts=dutyCount',
            type: 'POST',
            dataType: 'json',
            data: { groupid:groupid,first:first },
            success: function(data) {

                 //bootbox.alert(data['data']);
                $('#dutytable').html(data['data']);
                $('#countDuty').modal('show');
            }
        });
    }

    function recommend(dutyid){
        if(confirm("点赞会把您的5分转让给对方，您确定要点赞吗？")) {
            $.post(siteUrl + 'index.php?app=duty&ac=recommend', {'dutyid': dutyid}, function (rs) {

                if (rs == 0) {

                    tsNotice('一个赞消耗5分，您的积分不够点赞');

                } else {

                    window.location.reload()
                }
            })
        }
    }

</script>
{template footer}